module.exports = function ($scope, $resource, $modalInstance, FileUploader, bean, toaster){
    
    $scope.bean = {};
    var url = '';
    if(bean){
        $scope.bean = bean;
        url = '/api/as/mc/shopad/updateShopAD'
    } else {
        url = '/api/as/mc/shopad/addShopAD'
    }

    //添加
    $scope.ok = function () {
        if(!$scope.bean.title){
            toaster.warning({ title: '', body: '请填写广告标题'});
            return;
        }
        $resource(url, {}, {}).save($scope.bean, function(res){
          if (res.errcode === 0) {
              toaster.success({title: '', body: '成功'});
              $modalInstance.close();
          } else {
              toaster.error({title: '', body: '失败'});
          }
        });
    }

    $scope.uploader1 = new FileUploader({
        url: 'https://txy.juyouhx.com/Api/Api/ObjectToOss?topdir=shopad&selfdir=companycode'+Date.parse(new Date())
    });
    $scope.uploader1.filters.push({
        name: 'imageFilter',
        fn: function (item /*{File|FileLikeObject}*/, options) {
            var type = '|' + item.type.slice(item.type.lastIndexOf('/') + 1) + '|';
            return '|jpg|png|jpeg|bmp|gif|'.indexOf(type) !== -1;
        }
    });
    $scope.uploader1.onSuccessItem = function (fileItem, response, status, headers) {
        $scope.bean.ad_img = response.savename;
        $('#ad_img').removeAttr('height');
    };


    $scope.close = function () {
        $modalInstance.dismiss('cancel');
    }

};